﻿using ETask.Api.Dtos;
using ETask.Api.Services;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace ETask.Api.Controllers
{
    [Route("api/dept")]
    [ApiController]
    [Authorize]
    public class DeptController : ControllerBase
    {
        private IDeptService _deptService;

        public DeptController(IDeptService deptService)
        {
            _deptService = deptService;
        }

        [HttpPost("addDept")]
        public async Task<ApiResponse> AddDept([FromBody] CreateDeptDto createDeptDto)
        {
            return await _deptService.AddDept(createDeptDto);
        }

        [HttpPost("updateDept")]
        public async Task<ApiResponse> UpdateDept([FromBody] UpdateDeptDto updateDeptDto)
        {
            return await _deptService.UpdateDept(updateDeptDto);
        }

        [HttpPost("delById")]
        public async Task<ApiResponse> DelById([FromBody] PrimaryKey key)
        {
            return await _deptService.DelById(key.Id);
        }

        [HttpPost("getTree")]
        public async Task<ApiResponse> GetTree()
        {
            return await _deptService.GetTree();
        }

        [HttpPost("getList")]
        public async Task<ApiResponse> GetList([FromBody] DeptListParams listParams)
        {
            return await _deptService.GetList(listParams);
        }
    }
}
